package com.example.zyh.controller;


import com.example.zyh.pojo.Yezhu;
import com.example.zyh.service.YezhuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@ResponseBody
@RequestMapping("/Yezhu")
public class YezhuController {
    @Autowired
    private YezhuService yezhuService;
    @RequestMapping("/list")
    public List<Yezhu> select(){
        return yezhuService.select();
    }
    @RequestMapping("/add")
    public void add(Yezhu yezhu){
        yezhuService.addYezhu(yezhu);
    }
    @RequestMapping("/delete")
    public void delete(int id){
        yezhuService.deleteYezhu(id);
    }
    @RequestMapping("/update")
    public void update(Yezhu yezhu){
        yezhuService.updateYezhu(yezhu);
    }
    @RequestMapping("/selectlike")
    public List<Yezhu> selectlike(Yezhu yezhu){
        if(yezhu.getName()==null){
            yezhu.setName("");
        }
        if (yezhu.getSex()==null){
            yezhu.setSex("");
        }
        if (yezhu.getAge()==null){
            yezhu.setSex("");
        }
        if (yezhu.getAddress()==null){
            yezhu.setAddress("");
        }
        if (yezhu.getIdcard()==null){
            yezhu.setIdcard("");
        }
        return yezhuService.selectlike(yezhu);
    }

}
